package com.wandian.model
{
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.socket.ServerPacketProxy;
	import com.wandian.model.socket.net.Command;
	import com.wandian.model.vo.*;

	import org.puremvc.as3.patterns.proxy.Proxy;

	/**
	 * 游戏逻辑处理器
	 * @author long
	 * @Create  2012-10-26 下午01:26:43
	 * @QQ 108232706
	 * @version 1.0
	 */
	public class GameRoomProxy extends Proxy
	{
		private var _global:GameData;
		private var _serverPoxy:ServerPacketProxy;
		private var _inRoomData:InRoomPlayerDataProxy;
		public static const NAME:String="GameRoomProxy";

		public function GameRoomProxy(data:Object=null)
		{
			this._global=GameData.getInstance();
			super(NAME, data);
			return;
		}

		override public function onRegister():void
		{
			trace("GameRoomProxy onRegister");
			this._serverPoxy=facade.retrieveProxy(ServerPacketProxy.NAME) as ServerPacketProxy;
			this._inRoomData=facade.retrieveProxy(InRoomPlayerDataProxy.NAME) as InRoomPlayerDataProxy;
		}

		/**
		 * 响应坐下，整个房间都收到
		 */
		public function responseSitDown():void
		{
			var errorCode:int=this._serverPoxy.readByte();
			if (errorCode == 0)
			{
				this.sendNotification(CLZNoticeName.SITDOWN_ERR, errorCode);
				return;
			}
			var userid:int=this._serverPoxy.readInt();
			var objPlayer:PlayerVo=this._inRoomData.getInRoomPlayer(userid);
			objPlayer.seatId=this._serverPoxy.readInt();
			objPlayer.stake=this._serverPoxy.readFloat();
			objPlayer.money=this._serverPoxy.readFloat();

			objPlayer.callChip=0;
			//欢迎 %NAME% 坐下
			this.sendNotification(CLZNoticeName.CHAT_SYSTEM_TIP, GameData.replaceStrValue(GameData.tip["MSG_SIT_DOWN"], "NAME", objPlayer.name));
			this.sendNotification(CLZNoticeName.SITDOWN_RSP, objPlayer);
		}

		/**
		 * 响应坐下，整个房间都收到
		 */
		public function responseInGameRoom():void
		{
			var errorCode:int=this._serverPoxy.readByte();
			if (errorCode == 0)
			{
				this.sendNotification(CLZNoticeName.SITDOWN_ERR, errorCode);
				return;
			}
			var playerVo:PlayerVo=new PlayerVo();
			playerVo.userid=this._serverPoxy.readUInt();
//			playerVo.openId=this._serverPoxy.readInt();
//			playerVo.personId=this._serverPoxy.readInt();
			playerVo.sex=this._serverPoxy.readByte();
			playerVo.initSex=playerVo.sex;
			playerVo.name=this._serverPoxy.readString();
			playerVo.icon=this._serverPoxy.readString();
//			playerVo.vip=this._serverPoxy.readInt();
//			playerVo.gold=this._serverPoxy.readUInt();
			playerVo.money=this._serverPoxy.readFloat();
//			playerVo.sumGame=this._serverPoxy.readUInt();
//			playerVo.winGame=this._serverPoxy.readUInt();
//			playerVo.rank=this._serverPoxy.readUInt();
//			playerVo.winRank=this._serverPoxy.readUInt();
//			playerVo.giftPcate=this._serverPoxy.readUInt();
//			playerVo.giftPframe=this._serverPoxy.readUInt();
//			playerVo.banSpeak=this._serverPoxy.readInt();
//			playerVo.yellowvip=this._serverPoxy.readInt();
//			playerVo.isyearvip=this._serverPoxy.readInt();
			this._inRoomData.inRoom(playerVo);
			this.sendNotification(CLZNoticeName.IN_GAME_ROOM_RSP, playerVo);
		}

		/**
		 *
		 */
		public function responseOutGameRoom():void
		{
			var errorCode:int=this._serverPoxy.readByte();
			if (errorCode == 0)
			{
				this.sendNotification(CLZNoticeName.SITDOWN_ERR, errorCode);
				return;
			}
			var data:Object=new Object();
			data.userid=this._serverPoxy.readInt();
			this.sendNotification(CLZNoticeName.OUT_GAME_ROOM_RSP, data);
			this._inRoomData.outRoom(data.userid);
		}

		public function responseCloseSocketOutGameRoom():void
		{
			var errorCode:int=this._serverPoxy.readByte();
			if (errorCode == 0)
			{
				this.sendNotification(CLZNoticeName.SITDOWN_ERR, errorCode);
				return;
			}
			var data:Object=new Object();
			data.userid=this._serverPoxy.readInt();
			this.sendNotification(CLZNoticeName.OUT_GAME_ROOM_RSP, {userid: data.userid});
			(facade.retrieveProxy(InRoomPlayerDataProxy.NAME) as InRoomPlayerDataProxy).outRoom(data.userid);
//			this.sendNotification(CLZNoticeName.GAME_ROOM_SOCKET_CLOSE, roomVo);
		}

	}
}
